package com.zhou.jianzhi.controller.web;/**
 * @project jianzhi-server-master
 * @description
 * @author 黄嘉杰
 * @date 2025/1/23 11:22:18
 * @version 1.0
 */

import com.zhou.jianzhi.common.AjaxResult;
import com.zhou.jianzhi.entity.po.ForumPost;
import com.zhou.jianzhi.service.ForumPostService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @description: TODO
 * @author 黄嘉杰
 * @date 2025/1/23 11:22
 * @version 1.0
 */
@RestController
@RequestMapping("/forum")
public class ForumController {

    @Autowired
    private ForumPostService forumService;

    /**
     * 获取帖子列表
     * @param type 帖子类型(可选：全部/经验分享/问题解答/讨论交流)
     * @param page 页码
     * @param size 每页数量
     */
    @GetMapping("/list")
    public AjaxResult getPostList(
            @RequestParam(required = false) String type,
            @RequestParam(defaultValue = "1") Integer page,
            @RequestParam(defaultValue = "10") Integer size
    ) {
        return AjaxResult.success(forumService.getPostList(type, page, size));
    }

    /**
     * 发布新帖子
     */
    @PostMapping("/add")
    public AjaxResult addPost(@RequestBody ForumPost post) {
        forumService.addPost(post);
        return AjaxResult.success();
    }

    /**
     * 修改帖子
     */
    @PostMapping("/edit")
    public AjaxResult editPost(@RequestBody ForumPost post) {
        forumService.editPost(post);
        return AjaxResult.success();
    }

    /**
     * 删除帖子
     */
    @DeleteMapping("/{id}")
    public AjaxResult deletePost(@PathVariable Long id) {
        forumService.deletePost(id);
        return AjaxResult.success();
    }

    /**
     * 获取帖子详情
     */
    @GetMapping("/{id}")
    public AjaxResult getPostDetail(@PathVariable Long id) {
        return AjaxResult.success(forumService.getPostDetail(id));
    }
}
